Contents ----- Copyright Up Previous Next

Expressions

Additionally to simple strings, you can use expressions to set the value of an attribute. Inside an expressions, you can refer to other attributes to obtain their value, and you also can use several operators.

General Syntax

To assign an expression, you must start with a bracket (``('') after the equal-sign (``='') of the assignment. The expression ends with a bracket (``)'').

String constants must be enclosed inside any kind of quotes - different to values outside expressions, where the quotes can be omitted under certain circumstances.

For referring to the value of another attribute, simply use the name of it - without any enclosing quotes. The source attribute must exist, either by using <$define> or by being part of a macro declaration.

Furthermore it must contain a value, for example by means of <$let> or by setting it within a macro call. Attributes being defined without a default value or not being set within a macro call do not contain any data and therefor will have to be updated using <$let> before using them.

Example:
<$define image:string="hugo.gif">
<IMG SRC=(image) ALT="image">

will be converted to

<IMG SRC="hugo.gif" ALT="image">

Operators

Unary Operators

not expression
Negotiate (boolean) expression
set attribute
True, if attribute has been set (read: passed a value) within macro call.
defined attribute
True, if attribute was defined with <$macro> or <$define>
Exists(local uri)
True, if document at local URI exists (bool). This can also be specified as a Project Relative URI.
Example: Exists("index.html"), Exists(":image/next.gif")
fExists(filename)
True, if a file exists (bool). If you do not specify a full filename (including a device name), it will be relative to the source root directory.
Example: fExists("sepp:hugo/resi.hsc"), fExists("///child.txt"), fExists("include/global.hsc")
GetEnv(environment-variable)
Get value of an environment variable.
Example: GetEnv("Workbench")
GetFileSize(local uri)
Get size of a specific document. You can use the attribute HSC.Format.FileSize to change the appearence of the result.
Example: GetFileSize("../../download/hugo.lha"), GetFileSize(":nudes/resi.jpg")
GetGMTime()
Get current Greenwich Mean time. You can use the attribute HSC.Format.Time to change the appearence of the result.
GetTime()
Get current local time. You can use the attribute HSC.Format.Time to change the appearence of the result.

Binary Operators

expression = expression
string comparison (case insensitive)
expression + expression
string concatenation
little IN big
search for substring littel in big (case insensitive)
Example:
<$define name:string="hugo">
<$define here:string="here">

<IMG SRC=(name+".gif") ALT=(name+" was "+here)>
<$if cond=(name="hugo")>
This is hugo!
<$else>
Maybe it's sepp?
</$if>
<$if cond=("SePp" IN "hugo,sepp and resi")>
Sepp is among them.
</$if>
AmigaOS version: <(GetEnv ("KickStart"))>

will be converted to

<IMG SRC="hugo.gif" ALT="hugo was here">
This is hugo!
Sepp is among them.
AmigaOS version: 40.63

At least on my machine.

Boolean Expressions

If you pass an expression to a boolean attribute, the expression is evaluated as before. If the expression returned an empty string, the boolean attribute is interpreted as false. This will cause the attribute to be removed from the tag/macro-call.

Any none-empty string will set the attribute to true, resulting in a value equal to the name of attribute. (In html, writing ISMAP is short for ISMAP="ISMAP".)

Example:
<IMG SRC=(name) ALT="nufin" ISMAP=(name="map.gif")>

will be converted to

<IMG SRC="hugo.gif" ALT="nufin">

if name has been set to "hugo.gif", or to

<IMG SRC="map.gif" ALT="nufin" ISMAP>

if name has been set to "map.gif". Note that only the second call enables the boolean attribute ISMAP, while it gets stripped for the first call.

Priorities

Important: Different to most programming languages, hsc does not support priorities for different operators. Therefor, expressions are simply processed sequentially (Programmer's lazyness rules).

But you can use nested brackets within complex expressions.